package com.youlai.boot.modules.content.controller;

import com.youlai.boot.modules.content.service.LzArticleTagService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.modules.content.model.form.LzArticleTagForm;
import com.youlai.boot.modules.content.model.query.LzArticleTagQuery;
import com.youlai.boot.modules.content.model.vo.LzArticleTagVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 文章标签关联前端控制层
 *
 * @author lz0816
 * @since 2025-02-26 10:09
 */
@Tag(name = "文章标签关联接口")
@RestController
@RequestMapping("/api/v1/lzArticleTags")
@RequiredArgsConstructor
public class LzArticleTagController  {

    private final LzArticleTagService lzArticleTagService;

    @Operation(summary = "文章标签关联分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('modules.content:lzArticleTag:query')")
    public PageResult<LzArticleTagVO> getLzArticleTagPage(LzArticleTagQuery queryParams ) {
        IPage<LzArticleTagVO> result = lzArticleTagService.getLzArticleTagPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增文章标签关联")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('content:lzArticleTag:add')")
    public Result<Void> saveLzArticleTag(@RequestBody @Valid LzArticleTagForm formData ) {
        boolean result = lzArticleTagService.saveLzArticleTag(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取文章标签关联表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('content:lzArticleTag:edit')")
    public Result<LzArticleTagForm> getLzArticleTagForm(
        @Parameter(description = "文章标签关联ID") @PathVariable Long id
    ) {
        LzArticleTagForm formData = lzArticleTagService.getLzArticleTagFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改文章标签关联")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('content:lzArticleTag:edit')")
    public Result<Void> updateLzArticleTag(
            @Parameter(description = "文章标签关联ID") @PathVariable Long id,
            @RequestBody @Validated LzArticleTagForm formData
    ) {
        boolean result = lzArticleTagService.updateLzArticleTag(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除文章标签关联")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('content:lzArticleTag:delete')")
    public Result<Void> deleteLzArticleTags(
        @Parameter(description = "文章标签关联ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = lzArticleTagService.deleteLzArticleTags(ids);
        return Result.judge(result);
    }
}
